function getSelector(path){
  return path.reverse().filter(function (element){
    return element !== window && element !== document;
  }).map(function(element){
    let selector = ""
    if(element.id){
      selector = `${String.prototype.toLowerCase.call(element.nodeName)}#${element.id}`
    }else if(element.className && typeof element.className === 'string'){
      selector = `${String.prototype.toLowerCase.call(element.nodeName)}.${element.className}`
    }else{
      selector = String.prototype.toLowerCase.call(element.nodeName)
    }
    return selector
  }).join(' ')
}
export default function(pathToTarget){
  if(Array.isArray(pathToTarget)){
    return getSelector(pathToTarget)
  }else{
    const path = []
    let element = pathToTarget
    while(element){
      path.push(element)
      element = element.parentNode
    }
    return getSelector(path)
  }
}